package com.example.sicnuaccountingapp.ui.transaction

import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import com.example.sicnuaccountingapp.R
import com.example.sicnuaccountingapp.data.entity.Category
import com.example.sicnuaccountingapp.data.entity.Transaction
import com.example.sicnuaccountingapp.data.entity.TransactionType
import com.example.sicnuaccountingapp.databinding.DialogAddTransactionBinding
import com.google.android.material.tabs.TabLayout
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
class AddTransactionDialog : DialogFragment() {
    private var _binding: DialogAddTransactionBinding? = null
    private val binding get() = _binding!!

    private var transaction: Transaction? = null

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        _binding = DialogAddTransactionBinding.inflate(LayoutInflater.from(context))

        return AlertDialog.Builder(requireContext())
            .setTitle(if (transaction == null) getString(R.string.add_transaction) else getString(R.string.edit_transaction))
            .setView(binding.root)
            .setPositiveButton(R.string.save, null)
            .setNegativeButton(R.string.cancel, null)
            .create()
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }

    companion object {
        const val TAG = "AddTransactionDialog"

        fun newInstance(transaction: Transaction? = null): AddTransactionDialog {
            return AddTransactionDialog().apply {
                this.transaction = transaction
            }
        }
    }
} 